package handler

import (
	"gin.project.template/global"
	"gin.project.template/model"
	"gin.project.template/redis"
	"gin.project.template/util/jwt"
	"gin.project.template/util/response"
	"github.com/gin-gonic/gin"
)

func Login(c *gin.Context) {
	token := jwt.GenerateToken("1")
	response.SUCCESS(c, token)
}

func UserProfile(c *gin.Context) {

	//logger test
	global.Logger.Info("alive ok")

	//redis test
	_ = redis.Set("name1", "ydc", 100)
	_ = redis.Set("name2", "ydc", 0)
	value, _ := redis.Get("name")
	global.Logger.Info(value)

	//mysql test
	var user model.User
	err := global.MysqlDB.Model(&model.User{}).Where("id = ?", 1).First(&user)
	if err.Error != nil {
		response.ERROR(c, "ops")
		return
	}
	// 更新
	//global.MysqlDB.Model(&user).Updates(model.User{Name: "kali", Age: 20})

	type userVo struct {
		Name string `json:"name"`
		Age  int    `json:"age"`
	}

	userData := userVo{
		Name: "ydc",
		Age:  18,
	}
	response.SUCCESS(c, userData)
}
